// IMPORTANT: Read the license included with this code archive.

namespace Hosting
{
    using System.ComponentModel.Design;

    internal class MegaDesignerTransaction : DesignerTransaction
    {
        private readonly DesignerHost host;

        protected override void OnCommit()
        {
            // Fire the transaction events on the designer host
            this.host.OnTransactionClosing(true);
            this.host.OnTransactionClosed(true);
        }

        protected override void OnCancel()
        {
            // Fire the transaction events on the designer host
            this.host.OnTransactionClosing(false);
            this.host.OnTransactionClosed(false);
        }

        public MegaDesignerTransaction(DesignerHost host)
        {
            // Record a reference to the designer host, as we need this in order to tell it the transaction has been completed
            this.host = host;
        }

        public MegaDesignerTransaction(DesignerHost host, string description)
            : base(description)
        {
            // Record a reference to the designer host, as we need this in order to tell it the transaction has been completed
            this.host = host;
        }
    }
}